# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit toolchain

KEYWORDS="alpha amd64 arm arm64 hppa m68k mips ppc ppc64 s390 sh sparc x86"

src_prepare() {
	eapply "${FILESDIR}"/${PV}/00_gentoo-patchset.patch
	toolchain_src_prepare

	[[ $(tc-arch) == "mips" && ${DEFAULT_ABI} == "n64" ]] && eapply "${FILESDIR}"/${PV}/01_mips64-default-n64-abi.patch
	eapply "${FILESDIR}"/${PV}/02_fix-werror.patch

	use vanilla && return 0

	eapply "${FILESDIR}"/${PV}/postrelease/000_pr77450-77605-78185-78333.patch
	eapply "${FILESDIR}"/${PV}/postrelease/001_pr77943.patch
	eapply "${FILESDIR}"/${PV}/postrelease/002_pr70022-70484-70931-71452.patch
	eapply "${FILESDIR}"/${PV}/postrelease/003_pr61068.patch
	eapply "${FILESDIR}"/${PV}/postrelease/004_pr68963.patch
	eapply "${FILESDIR}"/${PV}/postrelease/005_pr62258.patch
	eapply "${FILESDIR}"/${PV}/postrelease/006_pr68814-69166-69239-69252.patch
	eapply "${FILESDIR}"/${PV}/postrelease/007_pr81395.patch
	eapply "${FILESDIR}"/${PV}/postrelease/008_pr58943.patch
	eapply "${FILESDIR}"/${PV}/postrelease/009_pr47992-69195-69238.patch
	eapply "${FILESDIR}"/${PV}/postrelease/010_pr96369.patch
	eapply "${FILESDIR}"/${PV}/postrelease/011_pr78378.patch
	eapply "${FILESDIR}"/${PV}/postrelease/012_pr106513.patch
	eapply "${FILESDIR}"/${PV}/postrelease/013_pr101442.patch
	eapply "${FILESDIR}"/${PV}/postrelease/014_pr69720.patch
	eapply "${FILESDIR}"/${PV}/postrelease/015_pr82697.patch
	eapply "${FILESDIR}"/${PV}/postrelease/016_pr68376-68670.patch
	eapply "${FILESDIR}"/${PV}/postrelease/017_pr94460.patch
	eapply "${FILESDIR}"/${PV}/postrelease/018_pr71083.patch
	eapply "${FILESDIR}"/${PV}/postrelease/019_pr67770.patch
	eapply "${FILESDIR}"/${PV}/postrelease/020_pr81505-81977-82084.patch
	eapply "${FILESDIR}"/${PV}/postrelease/021_pr67736.patch
	eapply "${FILESDIR}"/${PV}/postrelease/022_pr91927.patch
	eapply "${FILESDIR}"/${PV}/postrelease/023_pr82336.patch
	eapply "${FILESDIR}"/${PV}/postrelease/024_pr71086.patch
	eapply "${FILESDIR}"/${PV}/postrelease/025_pr65235.patch
	eapply "${FILESDIR}"/${PV}/postrelease/026_pr69891.patch
	eapply "${FILESDIR}"/${PV}/postrelease/027_pr70222.patch
	eapply "${FILESDIR}"/${PV}/postrelease/028_pr70370.patch
	eapply "${FILESDIR}"/${PV}/postrelease/029_pr70809.patch
	eapply "${FILESDIR}"/${PV}/postrelease/030_pr70184.patch
	eapply "${FILESDIR}"/${PV}/postrelease/031_pr69307.patch
	eapply "${FILESDIR}"/${PV}/postrelease/032_pr55771.patch
	eapply "${FILESDIR}"/${PV}/postrelease/033_pr54338-59787.patch
	eapply "${FILESDIR}"/${PV}/postrelease/034_pr70235.patch
	eapply "${FILESDIR}"/${PV}/postrelease/035_pr64905.patch
	eapply "${FILESDIR}"/${PV}/postrelease/036_pr91131.patch
	eapply "${FILESDIR}"/${PV}/postrelease/037_pr63347.patch
	eapply "${FILESDIR}"/${PV}/postrelease/038_pr60392.patch
	eapply "${FILESDIR}"/${PV}/postrelease/039_pr62052-69889.patch
	eapply "${FILESDIR}"/${PV}/postrelease/040_pr52413.patch
	eapply "${FILESDIR}"/${PV}/postrelease/041_pr77707.patch
	eapply "${FILESDIR}"/${PV}/postrelease/042_pr104147.patch
	eapply "${FILESDIR}"/${PV}/postrelease/043_pr56743.patch
	eapply "${FILESDIR}"/${PV}/postrelease/044_pr56810.patch
	eapply "${FILESDIR}"/${PV}/postrelease/045_pr38644.patch
	eapply "${FILESDIR}"/${PV}/postrelease/046_pr53690.patch
	eapply "${FILESDIR}"/${PV}/postrelease/047_pr75964.patch
	eapply "${FILESDIR}"/${PV}/postrelease/048_pr65358.patch
	eapply "${FILESDIR}"/${PV}/postrelease/049_pr79351.patch
	eapply "${FILESDIR}"/${PV}/postrelease/050_pr50199.patch
	eapply "${FILESDIR}"/${PV}/postrelease/051_pr23827.patch
	eapply "${FILESDIR}"/${PV}/postrelease/052_pr63408.patch
	eapply "${FILESDIR}"/${PV}/postrelease/053_pr61741.patch
	eapply "${FILESDIR}"/${PV}/postrelease/054_pr60718.patch
	eapply "${FILESDIR}"/${PV}/postrelease/055_pr58579.patch
	eapply "${FILESDIR}"/${PV}/postrelease/056_pr65734.patch
	eapply "${FILESDIR}"/${PV}/postrelease/057_pr55922.patch
	eapply "${FILESDIR}"/${PV}/postrelease/058_pr110044.patch
	eapply "${FILESDIR}"/${PV}/postrelease/059_pr82210.patch
	eapply "${FILESDIR}"/${PV}/postrelease/060_pr3698-86208.patch
	eapply "${FILESDIR}"/${PV}/postrelease/061_pr38313.patch
	eapply "${FILESDIR}"/${PV}/postrelease/062_pr54223-84276.patch
	eapply "${FILESDIR}"/${PV}/postrelease/063_pr66686-96097.patch
	eapply "${FILESDIR}"/${PV}/postrelease/064_pr69410.patch
	eapply "${FILESDIR}"/${PV}/postrelease/065_pr68995.patch
	eapply "${FILESDIR}"/${PV}/postrelease/066_pr98016.patch
	eapply "${FILESDIR}"/${PV}/postrelease/067_pr69116.patch
	eapply "${FILESDIR}"/${PV}/postrelease/068_pr52625.patch
	eapply "${FILESDIR}"/${PV}/postrelease/069_pr66575.patch
	eapply "${FILESDIR}"/${PV}/postrelease/070_pr61683.patch
	eapply "${FILESDIR}"/${PV}/postrelease/071_pr80176.patch
	eapply "${FILESDIR}"/${PV}/postrelease/072_pr67054.patch
	eapply "${FILESDIR}"/${PV}/postrelease/073_pr57063.patch
	eapply "${FILESDIR}"/${PV}/postrelease/074_pr61420.patch
	eapply "${FILESDIR}"/${PV}/postrelease/075_pr66957.patch
	eapply "${FILESDIR}"/${PV}/postrelease/076_pr60894.patch
	eapply "${FILESDIR}"/${PV}/postrelease/077_pr65879.patch
	eapply "${FILESDIR}"/${PV}/postrelease/078_pr62255.patch
	eapply "${FILESDIR}"/${PV}/postrelease/079_pr63149.patch
	eapply "${FILESDIR}"/${PV}/postrelease/080_pr64970.patch
	eapply "${FILESDIR}"/${PV}/postrelease/081_pr77812.patch
	eapply "${FILESDIR}"/${PV}/postrelease/082_pr49132.patch
	eapply "${FILESDIR}"/${PV}/postrelease/083_pr90107.patch
	eapply "${FILESDIR}"/${PV}/postrelease/084_pr53017-59211.patch
	eapply "${FILESDIR}"/${PV}/postrelease/085_pr60019.patch
	eapply "${FILESDIR}"/${PV}/postrelease/086_pr88754.patch
	eapply "${FILESDIR}"/${PV}/postrelease/087_pr16333-41426-59878-66895.patch
	eapply "${FILESDIR}"/${PV}/postrelease/088_pr22556.patch
	eapply "${FILESDIR}"/${PV}/postrelease/089_pr106421.patch
	eapply "${FILESDIR}"/${PV}/postrelease/090_pr105376.patch
	eapply "${FILESDIR}"/${PV}/postrelease/091_pr82314.patch
	eapply "${FILESDIR}"/${PV}/postrelease/092_pr60881.patch
	eapply "${FILESDIR}"/${PV}/postrelease/093_pr58704-58753-58930.patch
	eapply "${FILESDIR}"/${PV}/postrelease/094_pr60697.patch
	eapply "${FILESDIR}"/${PV}/postrelease/095_pr93140.patch
	eapply "${FILESDIR}"/${PV}/postrelease/096_pr87647.patch
	eapply "${FILESDIR}"/${PV}/postrelease/097_pr88870.patch
	eapply "${FILESDIR}"/${PV}/postrelease/098_pr84001.patch
	eapply "${FILESDIR}"/${PV}/postrelease/099_pr77919.patch
	eapply "${FILESDIR}"/${PV}/postrelease/100_pr81422.patch
	eapply "${FILESDIR}"/${PV}/postrelease/101_pr72801.patch
	eapply "${FILESDIR}"/${PV}/postrelease/102_pr79896.patch
	eapply "${FILESDIR}"/${PV}/postrelease/103_pr57728.patch
	eapply "${FILESDIR}"/${PV}/postrelease/104_pr69072-69100.patch
	eapply "${FILESDIR}"/${PV}/postrelease/105_pr78038.patch
	eapply "${FILESDIR}"/${PV}/postrelease/106_pr71103.patch
	eapply "${FILESDIR}"/${PV}/postrelease/107_pr72717.patch
	eapply "${FILESDIR}"/${PV}/postrelease/108_pr79641.patch
	eapply "${FILESDIR}"/${PV}/postrelease/109_pr69015.patch
	eapply "${FILESDIR}"/${PV}/postrelease/110_pr70457.patch
	eapply "${FILESDIR}"/${PV}/postrelease/111_pr58706.patch
	eapply "${FILESDIR}"/${PV}/postrelease/112_pr70778.patch
	eapply "${FILESDIR}"/${PV}/postrelease/113_pr54442.patch
	eapply "${FILESDIR}"/${PV}/postrelease/114_pr71063.patch
	eapply "${FILESDIR}"/${PV}/postrelease/115_pr69715-69574-69579.patch
	eapply "${FILESDIR}"/${PV}/postrelease/116_pr58635.patch
	eapply "${FILESDIR}"/${PV}/postrelease/117_pr65491.patch
	eapply "${FILESDIR}"/${PV}/postrelease/118_pr62070.patch
	eapply "${FILESDIR}"/${PV}/postrelease/119_pr58671.patch
	eapply "${FILESDIR}"/${PV}/postrelease/120_pr65554.patch
	eapply "${FILESDIR}"/${PV}/postrelease/121_pr70205.patch
	eapply "${FILESDIR}"/${PV}/postrelease/122_pr58749.patch
	eapply "${FILESDIR}"/${PV}/postrelease/123_pr61198.patch
	eapply "${FILESDIR}"/${PV}/postrelease/124_pr58003.patch
	eapply "${FILESDIR}"/${PV}/postrelease/125_pr44735.patch
	eapply "${FILESDIR}"/${PV}/postrelease/126_pr54440-71833.patch
	eapply "${FILESDIR}"/${PV}/postrelease/127_pr58647.patch
	eapply "${FILESDIR}"/${PV}/postrelease/128_pr59477.patch
	eapply "${FILESDIR}"/${PV}/postrelease/129_pr58545.patch
	eapply "${FILESDIR}"/${PV}/postrelease/130_pr52472.patch
	eapply "${FILESDIR}"/${PV}/postrelease/131_pr95009.patch
	eapply "${FILESDIR}"/${PV}/postrelease/132_pr62135.patch
	eapply "${FILESDIR}"/${PV}/postrelease/133_pr27100-59295.patch
	eapply "${FILESDIR}"/${PV}/postrelease/134_pr53756.patch
	eapply "${FILESDIR}"/${PV}/postrelease/135_pr59645.patch
	eapply "${FILESDIR}"/${PV}/postrelease/136_pr59633.patch
	eapply "${FILESDIR}"/${PV}/postrelease/137_pr107863.patch
	eapply "${FILESDIR}"/${PV}/postrelease/138_pr67046.patch
	eapply "${FILESDIR}"/${PV}/postrelease/139_pr71494.patch
	eapply "${FILESDIR}"/${PV}/postrelease/140_pr72809.patch
	eapply "${FILESDIR}"/${PV}/postrelease/141_pr39751.patch
	eapply "${FILESDIR}"/${PV}/postrelease/142_pr79361.patch
	eapply "${FILESDIR}"/${PV}/postrelease/143_pr85061.patch
	eapply "${FILESDIR}"/${PV}/postrelease/144_pr84900.patch
	eapply "${FILESDIR}"/${PV}/postrelease/145_pr58614.patch
	eapply "${FILESDIR}"/${PV}/postrelease/146_pr60736.patch
	eapply "${FILESDIR}"/${PV}/postrelease/147_pr59746-66707.patch
	eapply "${FILESDIR}"/${PV}/postrelease/148_pr60226.patch
	eapply "${FILESDIR}"/${PV}/postrelease/149_pr56852.patch
	eapply "${FILESDIR}"/${PV}/postrelease/150_pr69323.patch
	eapply "${FILESDIR}"/${PV}/postrelease/151_pr66461.patch
	eapply "${FILESDIR}"/${PV}/postrelease/152_pr77694.patch
	eapply "${FILESDIR}"/${PV}/postrelease/153_pr21113.patch
	eapply "${FILESDIR}"/${PV}/postrelease/154_pr49889.patch
	eapply "${FILESDIR}"/${PV}/postrelease/155_pr63786.patch
	eapply "${FILESDIR}"/${PV}/postrelease/156_pr57895.patch
	eapply "${FILESDIR}"/${PV}/postrelease/157_pr57848.patch
	eapply "${FILESDIR}"/${PV}/postrelease/158_pr89314.patch
	eapply "${FILESDIR}"/${PV}/postrelease/159_pr58560.patch
	eapply "${FILESDIR}"/${PV}/postrelease/160_pr89663.patch
	eapply "${FILESDIR}"/${PV}/postrelease/161_pr71251.patch
	eapply "${FILESDIR}"/${PV}/postrelease/162_pr78344.patch
	eapply "${FILESDIR}"/${PV}/postrelease/163_pr82872.patch
	eapply "${FILESDIR}"/${PV}/postrelease/164_pr58658.patch
	eapply "${FILESDIR}"/${PV}/postrelease/165_pr89876.patch
	eapply "${FILESDIR}"/${PV}/postrelease/166_pr85068.patch
	eapply "${FILESDIR}"/${PV}/postrelease/167_pr72707.patch
	eapply "${FILESDIR}"/${PV}/postrelease/168_pr70468.patch
	eapply "${FILESDIR}"/${PV}/postrelease/169_pr59641.patch
	eapply "${FILESDIR}"/${PV}/postrelease/170_pr71350.patch
	eapply "${FILESDIR}"/${PV}/postrelease/171_pr67803.patch
	eapply "${FILESDIR}"/${PV}/postrelease/172_pr69637.patch
	eapply "${FILESDIR}"/${PV}/postrelease/173_pr69095.patch
	eapply "${FILESDIR}"/${PV}/postrelease/174_pr84729.patch
	eapply "${FILESDIR}"/${PV}/postrelease/175_pr71627.patch
	eapply "${FILESDIR}"/${PV}/postrelease/176_pr58810.patch
	eapply "${FILESDIR}"/${PV}/postrelease/177_pr53492.patch
	eapply "${FILESDIR}"/${PV}/postrelease/178_pr58649.patch
	eapply "${FILESDIR}"/${PV}/postrelease/179_pr61046.patch
	eapply "${FILESDIR}"/${PV}/postrelease/180_pr58636.patch
	eapply "${FILESDIR}"/${PV}/postrelease/181_pr58612.patch
	eapply "${FILESDIR}"/${PV}/postrelease/182_pr58611.patch
	eapply "${FILESDIR}"/${PV}/postrelease/183_pr58511.patch
	eapply "${FILESDIR}"/${PV}/postrelease/184_pr58650.patch
	eapply "${FILESDIR}"/${PV}/postrelease/185_pr59120.patch
	eapply "${FILESDIR}"/${PV}/postrelease/186_pr59115.patch
	eapply "${FILESDIR}"/${PV}/postrelease/187_pr60374.patch
	eapply "${FILESDIR}"/${PV}/postrelease/188_pr58207.patch
	eapply "${FILESDIR}"/${PV}/postrelease/189_pr59707.patch
	eapply "${FILESDIR}"/${PV}/postrelease/190_pr58674.patch
	eapply "${FILESDIR}"/${PV}/postrelease/191_pr60253.patch
	eapply "${FILESDIR}"/${PV}/postrelease/192_pr58980.patch
	eapply "${FILESDIR}"/${PV}/postrelease/193_pr58700.patch
	eapply "${FILESDIR}"/${PV}/postrelease/194_pr58843.patch
	eapply "${FILESDIR}"/${PV}/postrelease/195_pr58871.patch
	eapply "${FILESDIR}"/${PV}/postrelease/196_pr59082.patch
	eapply "${FILESDIR}"/${PV}/postrelease/197_pr60252.patch
	eapply "${FILESDIR}"/${PV}/postrelease/198_pr60224.patch
	eapply "${FILESDIR}"/${PV}/postrelease/199_pr58705.patch
	eapply "${FILESDIR}"/${PV}/postrelease/200_pr31671.patch
	eapply "${FILESDIR}"/${PV}/postrelease/201_pr81304.patch
	eapply "${FILESDIR}"/${PV}/postrelease/202_pr69128.patch
	eapply "${FILESDIR}"/${PV}/postrelease/203_pr18969.patch
	eapply "${FILESDIR}"/${PV}/postrelease/204_pr28865.patch
	eapply "${FILESDIR}"/${PV}/postrelease/205_pr38757.patch
	eapply "${FILESDIR}"/${PV}/postrelease/206_pr52714.patch
	eapply "${FILESDIR}"/${PV}/postrelease/207_pr53477.patch
	eapply "${FILESDIR}"/${PV}/postrelease/208_pr53658.patch
	[[ $(tc-arch) != "arm" ]] && eapply "${FILESDIR}"/${PV}/postrelease/209_pr56564.patch
	eapply "${FILESDIR}"/${PV}/postrelease/210_pr60010.patch
	eapply "${FILESDIR}"/${PV}/postrelease/211_pr60784.patch
	eapply "${FILESDIR}"/${PV}/postrelease/212_pr63442.patch
	eapply "${FILESDIR}"/${PV}/postrelease/213_pr63567.patch
	eapply "${FILESDIR}"/${PV}/postrelease/214_pr65142.patch
	eapply "${FILESDIR}"/${PV}/postrelease/215_pr66731.patch
	eapply "${FILESDIR}"/${PV}/postrelease/216_pr66840.patch
	eapply "${FILESDIR}"/${PV}/postrelease/217_pr67281.patch
	eapply "${FILESDIR}"/${PV}/postrelease/218_pr68184.patch
	eapply "${FILESDIR}"/${PV}/postrelease/219_pr68680.patch
	eapply "${FILESDIR}"/${PV}/postrelease/220_pr69644.patch
	eapply "${FILESDIR}"/${PV}/postrelease/221_pr70549.patch
	eapply "${FILESDIR}"/${PV}/postrelease/222_pr72747.patch
	eapply "${FILESDIR}"/${PV}/postrelease/223_pr72863.patch
	eapply "${FILESDIR}"/${PV}/postrelease/224_pr77375.patch
	eapply "${FILESDIR}"/${PV}/postrelease/225_pr77767.patch
	eapply "${FILESDIR}"/${PV}/postrelease/226_pr78064.patch
	eapply "${FILESDIR}"/${PV}/postrelease/227_pr78416.patch
	eapply "${FILESDIR}"/${PV}/postrelease/228_pr78796.patch
	eapply "${FILESDIR}"/${PV}/postrelease/229_pr93272.patch
	eapply "${FILESDIR}"/${PV}/postrelease/230_pr79439.patch
	eapply "${FILESDIR}"/${PV}/postrelease/231_pr79969.patch
	eapply "${FILESDIR}"/${PV}/postrelease/232_pr80129.patch
	eapply "${FILESDIR}"/${PV}/postrelease/233_pr80362.patch
	eapply "${FILESDIR}"/${PV}/postrelease/234_pr80692.patch
	eapply "${FILESDIR}"/${PV}/postrelease/235_pr82274.patch
	eapply "${FILESDIR}"/${PV}/postrelease/236_pr62174.patch
	eapply "${FILESDIR}"/${PV}/postrelease/237_pr66279.patch
	eapply "${FILESDIR}"/${PV}/postrelease/238_pr93672.patch
	eapply "${FILESDIR}"/${PV}/postrelease/239_pr115646.patch
	eapply "${FILESDIR}"/${PV}/postrelease/240_pr115608.patch

	if use test ; then
		rm -rf gcc/testsuite/gcc.c-torture/execute/vfprintf-chk-1.c gcc/testsuite/gcc.c-torture/execute/vprintf-chk-1.c
		eapply "${FILESDIR}"/${PV}/postrelease/900_fix-known-test-fail.patch
		[[ $(tc-arch) == "arm" ]] && eapply "${FILESDIR}"/${PV}/postrelease/901_fix-arm-test-fail.patch
		# gcc-4.8.5 on aarch64, pch case random build crash
		[[ $(tc-arch) == "arm64" ]] && rm -rf gcc/testsuite/gcc.dg/pch gcc/testsuite/g++.dg/pch gcc/testsuite/objc.dg/pch
		[[ $(tc-arch) == "mips" ]] && eapply "${FILESDIR}"/${PV}/postrelease/902_fix-mips-test-fail.patch && \
			rm -rf gcc/testsuite/gcc.target/mips/mips-nonpic
	fi
}
